package lrscp.lib.io.Monitor;

public abstract class SimpleMonitor {
    public long mSize = -1;
    public long mProgress;
    public int mPercent = -1;
    public Object mTarget;
    private ProgressMonitor monitor = new ProgressMonitor() {
        @Override
        public void setSize(long size) {
            mSize = size;
            mProgress = 0;
            updateSize(size);
        }

        @Override
        public void setCurrentTarget(Object target) {
            mTarget = target;
            updateTarget(target);
        }

        @Override
        public void addProgress(long progress) {
            mProgress += progress;
            updateProgress(mProgress);

            int percentage = (int) (mProgress * 100 / mSize);
            percentage = percentage > 100 ? 100 : percentage;
            if (mPercent != percentage) {
                mPercent = percentage;
                updatePercent(mPercent);
            }
        }
    };

    public ProgressMonitor getMonitor() {
        return monitor;
    }

    public void updateSize(long size) {};

    public void updateTarget(Object target) {};

    public void updateProgress(long progress) {}

    public void updatePercent(int percent) {}
}
